package com.xzgj.fmmall.service.impl;

import com.xzgj.fmmall.dao.CategoryMapper;
import com.xzgj.fmmall.entity.Category;
import com.xzgj.fmmall.service.CategoryService;
import com.xzgj.fmmall.vo.CategoryVO;
import com.xzgj.fmmall.vo.ResStatus;
import com.xzgj.fmmall.vo.ResultVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public ResultVO selectAllCategories() {
        List<CategoryVO> categoryVOS = categoryMapper.selectAllCategories();
        for (CategoryVO cvo:categoryVOS){//一级
            System.out.println(cvo);
            for (CategoryVO cvo2:cvo.getCategories()){//二级
                System.out.println("\t" + cvo2);
                for (CategoryVO cvo3:cvo2.getCategories()){//三级
                    System.out.println("\t\t" + cvo3);

                }
            }
        }
        return new ResultVO(ResStatus.OK,ResStatus.SUCCESS,categoryVOS);
    }

    @Override
    public ResultVO selectChildrenCategoriesByParentId(int parentId) {
        List<CategoryVO> childrenCategories = categoryMapper.selectChildrenCategoriesByParentId(parentId);

        return new ResultVO(ResStatus.OK,ResStatus.SUCCESS,childrenCategories);
    }
}
